package com.yaser.beans;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.yaser.model.Stock;
import com.yaser.service.StockBo;

@Component
@Scope("session")
@Qualifier("userBean")
public class UserBean {

	@Autowired
	StockBo stockBo;
	
	private String name;

	private List<Stock> stockList;
	
	
	
	public UserBean() {
		super();
		stockList=new ArrayList<Stock>();
		
		Stock s1=new Stock();
		s1.setStockName("stock 1");
		s1.setStockCode("s1");
		
		Stock s2=new Stock();
		s2.setStockName("stock 2");
		s2.setStockCode("s2");
		
		Stock s3=new Stock();
		s3.setStockName("stock 3");
		s3.setStockCode("s3");
		
		stockList.add(s1);
		stockList.add(s2);
		stockList.add(s3);
		
		name="Liste boyu"+String.valueOf(stockList.size());
	}

	public void deneme() {
		System.out.println("inside method");
		/** insert **/
    	Stock stock = new Stock();
    	stock.setStockCode("7668");
    	stock.setStockName("HAIO");
    	stockBo.save(stock);
    	
    	/** select **/
    	Stock stock2 = stockBo.findByStockCode("7668");
    	System.out.println(stock2);
    	
    	/** update **/
    	stock2.setStockName("HAIO-1");
    	stockBo.update(stock2);
    	
    	/** delete **/
    	stockBo.delete(stock2);
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Stock> getStockList() {
		return stockList;
	}

	public void setStockList(List<Stock> stockList) {
		this.stockList = stockList;
	}
}
